class Solution {
public:
    bool isPerfectSquare(int num) 
    {
        if(num <= 1)
            return true;

        int low = 1;
        int height = 46340;

        while(low <= height)
        {
            int mid = (height + low) / 2;

            if(mid * mid == num)
                return true;
            else if(mid * mid > num)
                height = mid - 1;
            else low = mid + 1;
        }

        return false;
    }
};

//if中的条件为乘法和除法时运行结果不同